setwd("/data1/bsi/BORA_processing/devel/eqtl/parallelize_genotypingsurvival/1")
library(survival)
hazardrank<-read.table("hazardrank.txt",sep="\t",head=T)
clin<-read.delim("/data1/bsi/BORA_processing/devel/eqtl/parallelize_genotypingsurvival/clinical" ,sep="\t",quote="\"",dec=".",fill=TRUE,comment.char="", header=TRUE, col.names=c("SUBJECT","AGE","GENDER","OS","PFS","DFS","ALIVEOS","ALIVEPFS","ALIVEDFS","SITE"),as.is=c(TRUE,TRUE,FALSE,TRUE,TRUE,TRUE,TRUE,TRUE,TRUE,FALSE),colClasses=c("character","numeric","factor","numeric","numeric","numeric","integer","integer","integer","factor"))
clin$SUBJECT<-gsub("-",".",clin$SUBJECT)
#clin<-clin[which(clin[,7]!=0),]
tnum<-1
AUCrank<-matrix(nrow=nrow(hazardrank), ncol=1)
colnames(AUCrank)<-c("AUC")
rownames(AUCrank)<-rownames(hazardrank)
while(tnum<ncol(hazardrank)+1)
{
	dt <- merge(clin,t(hazardrank[tnum,]),by.y="row.names",by.x="SUBJECT")
	colnames(dt) <- c("SUBJECT","AGE","GENDER","OS","PFS","DFS","ALIVEOS","ALIVEPFS","ALIVEDFS","SITE","RANK")
	surv<-survConcordance(Surv(OS,ALIVEOS)~RANK,data=dt)
	AUC<-surv$concordance
	#print(c("AUC",AUC))
	AUCrank[1,tnum]<-AUC
	tnum =tnum+1
}
write.table(AUCrank,"AUC.txt",quote=FALSE,sep="\t",col.names=TRUE,row.names=TRUE)
